/**
* 版权所有：福建邮科电信业务部厦门研发中心 
*====================================================
* 文件名称: PageDirective.java
* 修订记录：
* No    日期				作者(操作:具体内容)
* 1.    2013-4-10			詹保山(创建:创建文件)
*====================================================
* 类描述：(说明未实现或其它不应生成javadoc的内容)
* 
*/
package com.devframe.component.ftlprocess.freemarker.directive;

import java.io.IOException;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.devframe.component.ftlprocess.FTLProcessGlobalConstants;
import com.devframe.component.ftlprocess.MyFTLProcessContextContainer;
import com.devframe.component.ftlprocess.engine.MyFTLProcessEngine;
import com.devframe.component.ftlprocess.meta.AskData;
import com.devframe.sys.util.assertion.Assert;

import freemarker.core.Environment;
import freemarker.ext.beans.BeanModel;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

public class PageDirective implements TemplateDirectiveModel {

	private static final Log logger=LogFactory.getLog(PageDirective.class);
	
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		Object fileObj=params.get("file");
		Assert.notNull(fileObj,"没有指定文件");
		BeanModel obj=(BeanModel)env.getDataModel().get(FTLProcessGlobalConstants.ASK_DATA_KEY);
		AskData askData=(AskData)obj.getWrappedObject();
		AskData newaskData=new AskData();
		String fileName=fileObj.toString();
		newaskData.setParams(askData.getAllParams());
		newaskData.setTemplateFile(fileName);
		MyFTLProcessEngine engine=(MyFTLProcessEngine)MyFTLProcessContextContainer.getInstance().getSpringBean("ftlProcessDefaultEngine");
		engine.execEngine(newaskData, env.getOut());	

	}

}
